package com.runshu.newsmartark.entity;

import android.os.Parcel;
import android.os.Parcelable;

import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.PrimaryKey;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.runshu.newsmartark.util.ListUtils;

import java.util.Arrays;
import java.util.List;

/**
 * Demo class
 *
 * @author yu
 * @date 2020/7/30
 * @decs：
 */
@Entity(tableName = "UserInfoEntity")
public class UserInfoEntity implements Parcelable {
    @PrimaryKey
    @ColumnInfo(name = "token")
    public Long id;
    @ColumnInfo(name = "icCard")
    private String icCard;
    @ColumnInfo(name = "username")
    private String username;
    @ColumnInfo(name = "usercode")
    private String usercode;
    @ColumnInfo(name = "mphone")
    private String mphone;
    @ColumnInfo(name = "admin")
    private boolean admin = true;
    @ColumnInfo(name = "facecode")
    private String  facecode;
    @ColumnInfo(name = "office")
    private String office;
    @ColumnInfo(name = "position")
    private String position;


    public String getFacecode() {
        return facecode == null ? "" : facecode;
    }

    public void setFacecode(String facecode) {
        this.facecode = facecode == null ? "" : facecode;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getIcCard() {
        return icCard == null ? "" : icCard;
    }

    public void setIcCard(String icCard) {
        this.icCard = icCard == null ? "" : icCard;
    }

    public String getUsername() {
        return username == null ? "" : username;
    }

    public void setUsername(String username) {
        this.username = username == null ? "" : username;
    }

    public String getUsercode() {
        return usercode == null ? "" : usercode;
    }

    public void setUsercode(String usercode) {
        this.usercode = usercode == null ? "" : usercode;
    }

    public String getMphone() {
        return mphone == null ? "" : mphone;
    }

    public void setMphone(String mphone) {
        this.mphone = mphone == null ? "" : mphone;
    }

    public boolean isAdmin() {
        return admin;
    }

    public void setAdmin(boolean admin) {
        this.admin = admin;
    }


    public static Creator<UserInfoEntity> getCREATOR() {
        return CREATOR;
    }

    public void setFacecode(byte[] facecode) {
        this.facecode = Arrays.toString(facecode);
    }

    public String getOffice() {
        return office == null ? "" : office;
    }

    public void setOffice(String office) {
        this.office = office == null ? "" : office;
    }

    public String getPosition() {
        return position == null ? "" : position;
    }

    public void setPosition(String position) {
        this.position = position == null ? "" : position;
    }

    public UserInfoEntity() {
    }

    @Override
    public String toString() {
        return "UserInfoEntity{" +
                "id=" + id +
                ", icCard='" + icCard + '\'' +
                ", username='" + username + '\'' +
                ", usercode='" + usercode + '\'' +
                ", mphone='" + mphone + '\'' +
                ", admin=" + admin +
                ", facecode='" + facecode + '\'' +
                ", office='" + office + '\'' +
                ", position='" + position + '\'' +
                '}';
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(this.id);
        dest.writeString(this.icCard);
        dest.writeString(this.username);
        dest.writeString(this.usercode);
        dest.writeString(this.mphone);
        dest.writeByte(this.admin ? (byte) 1 : (byte) 0);
        dest.writeString(this.facecode);
        dest.writeString(this.office);
        dest.writeString(this.position);
    }

    protected UserInfoEntity(Parcel in) {
        this.id = in.readLong();
        this.icCard = in.readString();
        this.username = in.readString();
        this.usercode = in.readString();
        this.mphone = in.readString();
        this.admin = in.readByte() != 0;
        this.facecode = in.readString();
        this.office = in.readString();
        this.position = in.readString();
    }

    public static final Parcelable.Creator<UserInfoEntity> CREATOR = new Parcelable.Creator<UserInfoEntity>() {
        @Override
        public UserInfoEntity createFromParcel(Parcel source) {
            return new UserInfoEntity(source);
        }

        @Override
        public UserInfoEntity[] newArray(int size) {
            return new UserInfoEntity[size];
        }
    };
}